/*
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2021-04-27     Administrator       the first version
 */
#ifndef APPLICATIONS_DEVICE_DEVICE_H_
#define APPLICATIONS_DEVICE_DEVICE_H_

#include <rtthread.h>
#include <rtdevice.h>
#include <board.h>
#include <cJSON.h>

// 红外控制
#define CTL_INFRARED_NUM 2 
#define CTL_INFRARED_PIN_1 GET_PIN(H, 3) //PE1, 红外检测引脚  KEY0
#define CTL_INFRARED_PIN_2 GET_PIN(H, 3) //PE1, 红外检测引脚  KEY0
enum {
    CTL_INFRARED_STATUS_ANYBODY = 1,
    CTL_INFRARED_STATUS_NOBODY = 0
};
typedef struct ctl_infrared_s
{
    long pin;
    int mode;
    int status;
    int value;
    int nobody_timeout;
    long nobody_last;
} ctl_infrared_s;
ctl_infrared_s infrared_arr[CTL_INFRARED_NUM]; 
// int ctl_infrared_change_flag();


// 门禁控制
#define CTL_DOOR_NUM 1 
#define CTL_DOOR_PIN_1 GET_PIN(H, 3) //PE1, 红外检测引脚  KEY0
#define CTL_DOOR_PIN_2 GET_PIN(H, 3) //PE1, 红外检测引脚  KEY0
enum {
    CTL_DOOR_STATUS_CLOSE = 0,
    CTL_DOOR_STATUS_OPEN = 1
};
typedef struct ctl_door_s
{
    long pin;
    int value;
} ctl_door_s;
ctl_door_s door_arr[CTL_DOOR_NUM]; 


// 开关控制
#define CTL_SWITCH_NUM 1 
#define CTL_SWITCH_PIN_1 GET_PIN(H, 3) //PE1, 红外检测引脚  KEY0
#define CTL_SWITCH_PIN_2 GET_PIN(H, 3) //PE1, 红外检测引脚  KEY0
enum {
    CTL_SWITCH_STATUS_OPEN = 0,
    CTL_SWITCH_STATUS_CLOSE = 1
};

typedef struct ctl_switch_s
{
    long pin;
    int value;
} ctl_switch_s;
ctl_switch_s switch_arr[CTL_SWITCH_NUM]; 


// 上传状态标准
int ctl_upload_flag;

void ctl_init();

#endif
